home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / ping / recvping.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  750b  |  36 lines

  1. /*
  2.  * Infinite loop to receive every ICMP packet received on the socket.
  3.  * For every packet that's received, we just call pr_pack() to look
  4.  * at it and print it.
  5.  */
  6.  
  7. #include    "defs.h"
  8.  
  9. recv_ping()
  10. {
  11.     register int        n;
  12.     int            fromlen;
  13.     struct sockaddr_in    from;
  14.  
  15.     for ( ; ; ) {
  16.         fromlen = sizeof(from);
  17.         if ( (n = recvfrom(sockfd, recvpack, sizeof(recvpack), 0,
  18.                 (struct sockaddr *) &from, &fromlen)) < 0) {
  19.             if (errno == EINTR)
  20.                 continue;    /* normal */
  21.             err_ret("recvfrom error");
  22.             continue;
  23.         }
  24.  
  25.         pr_pack(recvpack, n, &from);
  26.  
  27.         /*
  28.          * If we're only supposed to receive a certain number of
  29.          * packets, and we've reached the limit, stop.
  30.          */
  31.  
  32.         if (npackets && (nreceived >= npackets))
  33.             sig_finish();    /* does not return */
  34.     }
  35. }
  36.